package Leetcode;

public class problem43 {
    public static String multiply(String num1, String num2) {
        if(num1.equals("0") || num2.equals("0")){
            return "0";
        }

        char[] value = new char[num1.length() + num2.length()];

        for(int i = 0;i < num1.length(); i++){
            for(int j = 0;j < num2.length(); j++){
                value[i + j + 1] += (num1.charAt(i) - '0') * (num2.charAt(j) - '0');
            }
        }

        int plus = 0;
        for(int i = value.length - 1; i >= 0 ; i--){
            value[i] += plus;
            plus = value[i] / 10;
            value[i] %= 10;
        }

        int k = 0;
        for(; k < value.length ;k++){
            if(value[k] > 0){
                break;
            }
        }

        for (int i = k; i < value.length; i++) {
            value[i] += '0';
        }

        return new String(value, k, value.length - k);
    }

    public static void main(String[] args) {
        System.out.println(multiply("2","3"));
    }
}
